package DMSXL._2024.TX;

public class lemonadeChange {
    public static void main(String[] args) {
        int[] bills = {5,5,10,10,20};
        System.out.println(new lemonadeChange().lemonadeChange(bills));
    }
    public boolean lemonadeChange(int[] bills) {
        int have[] = new int[3];
        for (int i = 0; i < bills.length; i++) {
            if(bills[i] == 5){
                have[0] += 1;
            } else if (bills[i] == 10) {
                have[1] += 1;
                have[0] -= 1;
            }else {
                if(have[1] >= 1){
                    have[1] -= 1;
                    have[0] -= 1;
                    have[2] += 1;
                }else {
                    have[0] -= 3;
                    have[2] += 1;
                }
            }
            //判断合法性
            for (int j = 0; j < have.length; j++) {
                if(have[j] < 0){
                    return false;
                }
            }
        }
        return true;
    }
}
